package cn.yuysaln.domain.strategy.service.rule.tree.factory;

import cn.yuysaln.domain.strategy.model.valobj.RuleLogicCheckTypeVO;
import cn.yuysaln.domain.strategy.model.valobj.RuleTreeVO;
import cn.yuysaln.domain.strategy.service.rule.tree.ILogicTree;
import cn.yuysaln.domain.strategy.service.rule.tree.factory.engine.DecisionTreeEngine;
import cn.yuysaln.domain.strategy.service.rule.tree.factory.engine.IDecisionTreeEngine;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 创建决策树
 */
@Service
public class DefaultTreeFactory {
    private final Map<String, ILogicTree> logicTreeNodeGroup;  //所有的Tree实例节点集合
    public DefaultTreeFactory(Map<String, ILogicTree> logicTreeNodeGroup) {
        this.logicTreeNodeGroup = logicTreeNodeGroup;
    }

    /**
     * 开启规则树的过滤逻辑
     * @param ruleTreeVO 规则树
     * @return 规则树引擎
     */
    public IDecisionTreeEngine openLogicTree(RuleTreeVO ruleTreeVO){
        return new DecisionTreeEngine(logicTreeNodeGroup,ruleTreeVO);
    }


    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class TreeActionEntity {
        /**
         * 当前状态
         */
        private RuleLogicCheckTypeVO ruleLogicCheckTypeVO;
        /**
         * 过滤后所携带的数据
         */
        private StrategyAwardVO strategyAwardVO;
    }


    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class StrategyAwardVO {
        private Integer awardId;
        private String awardRuleValue;
    }
}
